Skip to content

BDMS-430 Migrate legacy FieldParameters chemistry table#394

Merged
jirhiker merged 12 commits into
stagingfrom
kas-nma-field-parameters-migration
Jan 16, 2026
Merged

BDMS-430 Migrate legacy FieldParameters chemistry table#394
jirhiker merged 12 commits into
stagingfrom
kas-nma-field-parameters-migration

Conversation

@ksmuczynski

Copy link
Copy Markdown
Contributor

Why

This PR addresses the following problem / context:

  • Legacy FieldParameters data needed an ORM model, migration, tests, and transfer path to backfill into the new schema
  • Ensure FieldParameters records are validated against existing ChemistrySampleInfo entries

How

Implementation summary - the following was changed / added / removed:

  • Added NMAFieldParameters model to db/nma_legacy.py
    • Created Alembic migration alembic/versions/c1d2e3f4a5b6_create_nma_field_parameters.py to build the legacy table
    • Added unit tests in tests/test_field_parameters_legacy.py to validate mappings and CRUD behavior
    • Implemented transfer script transfers/field_parameters_transfer.py with FK validation and batch upsert

Notes

Any special considerations, workarounds, or follow-up work to note?

  • Transfer depends on ChemistrySampleInfo being populated first

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements migration infrastructure for legacy FieldParameters chemistry data by adding an ORM model, Alembic migration, comprehensive tests, and a transfer script with foreign key validation.

Changes:

  • Added NMAFieldParameters model with proper foreign key relationships to ChemistrySampleInfo
  • Created Alembic migration to build the legacy table structure with indexes
  • Implemented transfer script with batch upsert, FK validation, and orphan prevention

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
transfers/field_parameters_transfer.py Transfer script with batch upsert logic and ChemistrySampleInfo FK validation
tests/test_field_parameters_legacy.py Comprehensive CRUD and relational integrity tests for the new model
db/nma_legacy.py NMAFieldParameters model with relationship to ChemistrySampleInfo
alembic/versions/c1d2e3f4a5b6_create_nma_field_parameters.py Migration to create legacy table structure with indexes

Comment thread db/nma_legacy.py Outdated
Comment thread alembic/versions/c1d2e3f4a5b6_create_nma_field_parameters.py Outdated

@chasetmartin chasetmartin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great! The two copilot comments do seem relevant.

Migration ran ok for me, and tests passed. I think the one missing item is updating the transfer.py file so that that we can run and test the transfer of field parameters. I would look to this Stratigraphy PR for how to update transfer.py:
https://github.com/DataIntegrationGroup/OcotilloAPI/pull/393/changes#diff-d2d33d2e5666e926931898df688d5d66a04e7d8148800dec2399b1de947e1fbf

Remove space in `Chemistry SampleInfoFieldParameters` index

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings January 16, 2026 16:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Remove space in `Chemistry SampleInforFieldParameters` index name

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings January 16, 2026 16:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings January 16, 2026 23:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

assert record.sample_pt_id == sample_info.sample_pt_id
assert record.field_parameter is None
assert record.units is None
assert record.sample_value == 0

Copilot AI Jan 16, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion expects sample_value to default to 0, but the test creates a record without explicitly setting this field. This test is verifying the server_default behavior from the model/migration. However, SQLAlchemy ORM won't populate server defaults until after a commit and refresh. The assertion should occur after session.refresh(record) to ensure the server default is loaded from the database.

Copilot uses AI. Check for mistakes.
@jirhiker jirhiker merged commit 3a8fdad into staging Jan 16, 2026
6 checks passed
@TylerAdamMartinez TylerAdamMartinez deleted the kas-nma-field-parameters-migration branch February 26, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants